//import {getxm,getxm1} from "api.js";
//import zzjg from "../../../../../themes/admin_default/xmgl/assets/utils/zzjg.js";
//import role from "../../../../../themes/admin_default/xmgl/assets/utils/role.js";
//import user from "../../../../../themes/admin_default/xmgl/assets/utils/userpublic.js";
//import { unixtimetostr } from "../../../../../themes/admin_default/xmgl/assets/utils/tools.js";

import api from "../utils/api.js";
import tools from "../utils/tools.js";

axios.defaults.headers.post['Content-Type'] = 'application/json';

// 注册
Vue.component('xtest', {
    template: '<h1>自定义组件!</h1>'
});

var vm = new Vue({
    el: '#app',
    mounted: function () {
        // 访问组件的 DOM 元素
        //console.log(this.$el)
        let that = this;
        // 使用 $nextTick 方法访问父组件的数据
        this.$nextTick(() => {
            console.log('使用 $nextTick 方法访问父组件的数据', this.form)

            //console.log('unionid:', this.$refs.union_id.value);

            this.init_data();
        })
        // 监听数据变化
        this.$watch('data', () => {
            console.log('data changed')
        })
        // 在组件销毁时取消异步操作
        this.$once('hook:beforeDestroy', () => {
            this.cancelAsyncTask()
        })
    },
    data: function () {
        return {
            props: { multiple: true },//选择框开多选

            zzjgList: [],   //
            roleList: [],

            form: {
                user_login: '',
            },
            rules: {
                //zzjgValue: [{type: 'array', required: true, message: '请选择所属机构', trigger:  'change' }],
                //roleValue: [{type: 'array', required: true, message: '请选择职务', trigger:  'change' }],
                //pass: [{ validator: validatePass, trigger: 'blur' }],
                //checkPass: [{ validator: validatePass2, trigger: 'blur' }],
            }
        }
    },

    methods: {
        changeZzjgCasc(e) {
            console.log("选中的值:", e)
            this.$nextTick(() => {
                // 级联多选专业 的最后一项的数组
                let newArr = []
                this.form.zzjgValue.map((item) => {
                    newArr.push(item[item.length - 1])
                })
                this.form.zzjgValue = newArr;
                console.log('转换后的zzjgValue：', newArr);
            });
        },
        changeRoleCasc(e) {
            console.log("选中的值:", e)
            this.$nextTick(() => {
                // 级联多选专业 的最后一项的数组
                let newArr = []
                this.form.roleValue.map((item) => {
                    newArr.push(item[item.length - 1])
                })
                this.form.roleValue = newArr;
                console.log('转换后的roleValue:', newArr);
            });
        },
        onSubmit(form) {
            let that = this;
            this.$refs.form.validate((valid) => {
                if (valid) {
                    console.log('表单数据验证通过', that.form);

                    //转换日期为UNIX时间
                    //let d = new Date(that.form.birthday).getTime()/1000;
                    //that.form.birthday = d;

                    util.webReg(that.form)
                        .then((res) => {
                            console.log('提交表单返回', res);
                            //注册成功，跳转到重新登录页面
                            this.$message({
                                showClose: true,
                                message: '微信用户注册成功，跳转页面!',
                                type: 'success',
                                center: true
                            });
                            location.replace("/admin");
                        })
                        .catch((res) => {
                            console.log('提交表单返回错误', res);
                            this.$message({
                                showClose: true,
                                message: res.msg,
                                type: 'error',
                                center: true
                            });
                        });

                } else {
                    console.log('表单数据验证有误');
                    return false;
                }
            });
        },
        onCancel(form) {
            location.assign("/");
        },
        resetForm(form) {
            this.$refs[form].resetFields();
        },
        backurl() {
            window.history.back();  //返回上一页
        },
    },
});

vm.unixtimetostr = tools.unixtimetostr;

vm.init_data = function () {
    let that = this;
}


